// Copyright (c) MatrixFramework. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System;
using Volo.Abp.Domain.Entities.Auditing;

namespace PhotoGalleryService.Photos;

/// <summary>
/// 照片实体
/// </summary>
public class Photo : AuditedAggregateRoot<Guid>
{
    /// <summary>
    /// 文件名
    /// </summary>
    public string FileName { get; set; } = string.Empty;

    /// <summary>
    /// 原始文件名
    /// </summary>
    public string OriginalFileName { get; set; } = string.Empty;

    /// <summary>
    /// 文件路径
    /// </summary>
    public string FilePath { get; set; } = string.Empty;

    /// <summary>
    /// 文件大小（字节）
    /// </summary>
    public long FileSize { get; set; }

    /// <summary>
    /// MIME类型
    /// </summary>
    public string MimeType { get; set; } = string.Empty;

    /// <summary>
    /// 文件哈希值（用于去重）
    /// </summary>
    public string FileHash { get; set; } = string.Empty;

    /// <summary>
    /// 照片标题
    /// </summary>
    public string? Title { get; set; }

    /// <summary>
    /// 照片描述
    /// </summary>
    public string? Description { get; set; }

    /// <summary>
    /// 拍摄时间
    /// </summary>
    public DateTime? TakenAt { get; set; }

    /// <summary>
    /// 纬度
    /// </summary>
    public double? Latitude { get; set; }

    /// <summary>
    /// 经度
    /// </summary>
    public double? Longitude { get; set; }

    /// <summary>
    /// 位置描述
    /// </summary>
    public string? Location { get; set; }

    /// <summary>
    /// 相机型号
    /// </summary>
    public string? CameraModel { get; set; }

    /// <summary>
    /// 照片宽度
    /// </summary>
    public int? Width { get; set; }

    /// <summary>
    /// 照片高度
    /// </summary>
    public int? Height { get; set; }

    /// <summary>
    /// 是否公开
    /// </summary>
    public bool IsPublic { get; set; } = false;

    /// <summary>
    /// 标签（JSON格式存储）
    /// </summary>
    public string? Tags { get; set; }

    /// <summary>
    /// 缩略图路径
    /// </summary>
    public string? ThumbnailPath { get; set; }

    /// <summary>
    /// 中等尺寸图片路径
    /// </summary>
    public string? MediumPath { get; set; }

    protected Photo()
    {
    }

    public Photo(
        Guid id,
        string fileName,
        string originalFileName,
        string filePath,
        long fileSize,
        string mimeType,
        string fileHash
    )
    {
        Id = id;
        FileName = fileName;
        OriginalFileName = originalFileName;
        FilePath = filePath;
        FileSize = fileSize;
        MimeType = mimeType;
        FileHash = fileHash;
    }

    /// <summary>
    /// 更新照片信息
    /// </summary>
    /// <param name="title">标题</param>
    /// <param name="description">描述</param>
    /// <param name="tags">标签</param>
    /// <param name="isPublic">是否公开</param>
    public void UpdatePhotoInfo(string? title, string? description, string? tags, bool isPublic)
    {
        Title = title;
        Description = description;
        Tags = tags;
        IsPublic = isPublic;
    }

    /// <summary>
    /// 更新地理位置信息
    /// </summary>
    /// <param name="latitude">纬度</param>
    /// <param name="longitude">经度</param>
    /// <param name="location">位置描述</param>
    public void UpdateLocation(double? latitude, double? longitude, string? location)
    {
        Latitude = latitude;
        Longitude = longitude;
        Location = location;
    }

    /// <summary>
    /// 更新拍摄时间
    /// </summary>
    /// <param name="takenAt">拍摄时间</param>
    public void UpdateTakenTime(DateTime? takenAt)
    {
        TakenAt = takenAt;
    }

    /// <summary>
    /// 更新相机信息
    /// </summary>
    /// <param name="cameraModel">相机型号</param>
    /// <param name="width">宽度</param>
    /// <param name="height">高度</param>
    public void UpdateCameraInfo(string? cameraModel, int? width, int? height)
    {
        CameraModel = cameraModel;
        Width = width;
        Height = height;
    }

    /// <summary>
    /// 更新处理后的图片路径
    /// </summary>
    /// <param name="thumbnailPath">缩略图路径</param>
    /// <param name="mediumPath">中等尺寸图片路径</param>
    public void UpdateProcessedPaths(string? thumbnailPath, string? mediumPath)
    {
        ThumbnailPath = thumbnailPath;
        MediumPath = mediumPath;
    }
}